package com.zrrd.gmall.product.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.zrrd.gmall.common.result.Result;
import com.zrrd.gmall.model.product.BaseAttrInfo;
import com.zrrd.gmall.model.product.BaseAttrValue;
import com.zrrd.gmall.product.service.BaseAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseAttrController {
    @Autowired
    private BaseAttrService baseAttrService;
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> attrInfoList(@PathVariable("category1Id")Long category1Id,
                                                   @PathVariable("category2Id")Long category2Id,
                                                   @PathVariable("category3Id")Long category3Id){
        List<BaseAttrInfo> infoList = baseAttrService.getAttrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(infoList);
    }
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        baseAttrService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }
    //根据平台属性id获取属性对象
    @GetMapping("/getAttrValueList/{attrId}")
    public Result<List<BaseAttrValue>> getAttrValueList(@PathVariable("attrId") Long attrId){
        List<BaseAttrValue> attrInfo = baseAttrService.getAttrInfo(attrId);
        return Result.ok(attrInfo);
    }
}
